<template>
  <div>
    <el-table
    ref="multipleTable"
    :data="tableData"
    tooltip-effect="dark"
    style="width: 100%"
    @selection-change="handleSelectionChange">
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column
      label="姓名">
      <template slot-scope="scope">{{ scope.row.auditorNm }}</template>
    </el-table-column>
    <el-table-column
      prop="rlNm"
      label="职位">
    </el-table-column>
  </el-table>
  <el-row :gutter="20" justify="space-around" type="flex" style="margin-top:20px;">
    <el-col :span="12">
      <el-button style="float:right;" @click="cancelshare()">取 消</el-button>
    </el-col>
    <el-col :span="12">
      <el-button style="float:left;" type="primary" @click="sureshare()">确 定</el-button>
    </el-col>
  </el-row>
  </div>
</template>
<script>
import axios from 'axios'
export default {
  props: {},
  components: {},
  data(){
    return {
      tableData: [],
      multipleSelection: []
    }
  },
  mounted () {
  },
  methods: {
    // 取消分享
    cancelshare () {
      this.$emit('cancelshare')
    },
    // 确认分享
    sureshare () {
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        this.multipleSelection.forEach(item => {
          let index = this.tableData.findIndex(element => element === item)
          console.log(index)
          if (index != -1) {
            this.tableData[index].checkflag = true
          }
        })
      }
      console.log(this.tableData)
      this.$emit('sureshare',this.tableData)
    },
    // 查询人员
    opened () {
      console.log('查询列表')
      let info = {
      "userId":"1001",
      "auditGrpId":"10000001",
      "unknownFileId":"abc12345",
      "unknownFileType":"10"
      }
    this.tableData = []
    axios.post('http://128.16.180.47:7111/fileShare/authInfo', info).then((response) => {
          console.log(response)
          if (response && response.data && response.data.tOesGrpMembBoList && response.data.tOesGrpMembBoList.length > 0) {
            response.data.tOesGrpMembBoList.forEach(item =>{
              this.tableData.push({
                shareFlag: item.shareFlag,
                userId: item.tOesGrpMemb.userId,
                auditGrpId: item.tOesGrpMemb.auditGrpId,
                auditorId: item.tOesGrpMemb.auditorId,
                auditorNm: item.tOesGrpMemb.auditorNm,
                rlNm: item.tOesGrpMemb.rlNm
              })
            })
            // 反显已经共享过的
            let arr = []
            this.tableData.forEach(item =>{
              if (item.shareFlag === true) {
                arr.push(item)
              }
            })
            this.toggleSelection(arr)
          }
        }).catch((response) => {
          console.log(response)
        })
    },
    toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
    handleSelectionChange(val) {
        this.multipleSelection = val
      }
  }
}
</script>
<style lang="less" scoped>

</style>